package nl.ruudshuis.data;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nl.ruudshuis.dao.VeilingDao;
import nl.ruudshuis.db.DBmanager;

/**
 * Servlet implementation class VeilingController
 */
public class VeilingController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private ServletContext context;   
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public VeilingController() {
        super();
    }
    
    public void init() throws ServletException{
    	context = getServletContext();
    	DBmanager myDb = (DBmanager)context.getAttribute("dbman");
    	if(myDb == null){
    		myDb = DBmanager.getInstance();
    		context.setAttribute("dbman", myDb);
    	}
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		VeilingDao d = new VeilingDao((DBmanager)context.getAttribute("dbman"));
		
		request.setAttribute("veilingen", d.getVeilingen());
		RequestDispatcher view = request.getRequestDispatcher("/WEB-INF/veilingen.jsp");
		view.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
